﻿using AutoMapper.Internal.Mappers;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ThridGroup.ERP.DTO;
using ThridGroup.ERP.ProductionSystem;

namespace ThridGroup.ERP.Web.Controllers.ProductionSystem
{
    public class EquipmentTypeController : Controller
    {
        private readonly EquipmentTypeService _equipmentTypeService;
        public EquipmentTypeController(EquipmentTypeService equipmentTypeService)
        {
            _equipmentTypeService = equipmentTypeService;
        }
        /// <summary>
        /// 列表
        /// </summary>
        /// <returns></returns>
        public IActionResult EquipmentTypeList()
        {
            return View();
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <returns></returns>
        public IActionResult EquipmentTypeCreate()
        {
            return View();
        }
        //编辑
        public IActionResult EquipmentTypeUpdate()
        {
            return View();
        }
        [HttpPost]
        public async Task<int> AddEquipmentType(EquipmentTypeDTO equipmentType)
        {
            return await _equipmentTypeService.AddEquipmentType(equipmentType);
        }
        [HttpDelete]
        public async Task<int> DeleteWorkmanship(int equipmentTypeId)
        {
            return await _equipmentTypeService.DeleteWorkmanship(equipmentTypeId);
        }
        [HttpGet]
        public async Task<EquipmentTypeDTO> FanEquipmentType(int equipmentTypeId)
        {
            return await _equipmentTypeService.FanEquipmentType(equipmentTypeId);
        }
        [HttpGet]
        public async Task<JsonResult> GetEquipmentType(int pageIndex = 1, int pageSize = 10)
        {
            var list = await _equipmentTypeService.GetEquipmentType();
            var result = list.OrderBy(c=>c.Id).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToList();
            return Json(new
            {
                code = 0,
                msg = "",
                count = list.Count,
                data = result,
            });
        }
        [HttpPost]
        public async Task<int> UpdateEquipmentType(EquipmentTypeDTO equipmentType)
        {
            return await _equipmentTypeService.UpdateEquipmentType(equipmentType);
        }
    }
}
